package com.wzcl.app.dao.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.wzcl.app.dao.model.common.Base;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.util.List;

@Data
@Entity
@ApiModel(value = "资源表")
@Table(name = "app_resource",
        uniqueConstraints = {
                @UniqueConstraint(columnNames = {"name"})
        }
)
public class AppResource implements Base {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ApiModelProperty(value = "资源路径")
    private String name;

    @ApiModelProperty(value = "描述")
    private String description;

    @JSONField(serialize = false)
    @ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
    @ApiModelProperty(value = "权限")
    @JoinTable(name = "role_resource",
            joinColumns = {@JoinColumn(name = "resource_id")},
            inverseJoinColumns = {@JoinColumn(name = "role_id")})
    private List<AppRole> roleList;
}
